package learn.advance.object1;

import org.omg.CORBA.PUBLIC_MEMBER;

import javax.swing.*;
import java.util.ArrayList;
import java.util.Objects;
import java.util.Random;

class Person {
    private String name_;
    private int age_;

    public Person() {

    }

    public Person(String name, int age) {
        this.name_ = name;
        this.age_ = age;
    }

    @Override
    public String toString() {
        return "name:" + name_ + "age:" + age_;
    }

    @Override
    public boolean equals(Object obj) {
        if (obj == this)
            return true;

        if (obj == null)
            return false;

        if (obj instanceof Person) {
            Person p = (Person) obj;
            boolean b = this.name_.equals(p.name_) && this.age_ == p.age_;
            return b;
        }
        return false;
    }

    @Override
    public int hashCode(){
        return Objects.hash(name_,age_);
    }

    public String GetName(){
        return name_;
    }

    public void Setname(String name){
        this.name_=name;
    }
}


class Dem01ToString{
    private ArrayList<Integer> list;

    public static void Test(){
        Person p=new Person("小明",18);
        String s=p.toString();

        System.out.println(s);
        System.out.println(p);

        System.out.println("==================");

        Random r=new Random();
        System.out.println(r);

        ArrayList<Integer> list= new ArrayList<>();
        list.add(1);
        list.add(2);
        System.out.println(list);
    }
}



public class TestObject {
    public static void main(String[] args) {
        Dem01ToString.Test();
    }

}
